package cn.edu.sgu.www.mhxysy.service.chongwu.impl;

import cn.edu.sgu.www.mhxysy.dto.chongwu.ChongwuZizhiDTO;
import cn.edu.sgu.www.mhxysy.entity.chongwu.ChongwuZizhi;
import cn.edu.sgu.www.mhxysy.mapper.chongwu.ChongwuZizhiMapper;
import cn.edu.sgu.www.mhxysy.service.chongwu.ChongwuZizhiService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Service
public class ChongwuZizhiServiceImpl implements ChongwuZizhiService {

	private final ChongwuZizhiMapper chongwuZizhiMapper;

	@Autowired
	public ChongwuZizhiServiceImpl(ChongwuZizhiMapper chongwuZizhiMapper) {
		this.chongwuZizhiMapper = chongwuZizhiMapper;
	}

	@Override
	public void updateByChongwuId(ChongwuZizhiDTO chongwuZizhiDTO) {
		ChongwuZizhi chongwuZizhi = new ChongwuZizhi();

		chongwuZizhi.setGjzz(chongwuZizhiDTO.getGjzz());
		chongwuZizhi.setFyzz(chongwuZizhiDTO.getFyzz());
		chongwuZizhi.setTlzz(chongwuZizhiDTO.getTlzz());
		chongwuZizhi.setFlzz(chongwuZizhiDTO.getFlzz());
		chongwuZizhi.setSdzz(chongwuZizhiDTO.getSdzz());
		chongwuZizhi.setChengzhang(chongwuZizhiDTO.getChengzhang());

		UpdateWrapper<ChongwuZizhi> updateWrapper = new UpdateWrapper<>();

		updateWrapper.eq("chongwu_id", chongwuZizhiDTO.getChongwuId());

		chongwuZizhiMapper.update(chongwuZizhi, updateWrapper);
	}

	@Override
	public ChongwuZizhi selectByChongwuId(String chongwuId) {
		QueryWrapper<ChongwuZizhi> queryWrapper = new QueryWrapper<>();

		queryWrapper.eq("chongwu_id", chongwuId);

		return chongwuZizhiMapper.selectOne(queryWrapper);
	}

}